package mint.modules.generator.expression;

import java.util.Formatter;
import java.util.List;

import org.antlr.runtime.tree.Tree;

import mint.MintLexer;
import mint.modules.generator.Scope;
import mint.modules.type.Type;

public class PrimaryNode extends Expression {
	Expression expr;

	public PrimaryNode(Scope theParent, ExpressionType exprType, Tree primaryExprTree) {
		super(theParent, exprType);
		
		if(primaryExprTree.getType() == MintLexer.EXPR)
			expr = new ExprNode(theParent, exprType, primaryExprTree);
		else if (primaryExprTree.getType() == MintLexer.THIS)
			expr = new ThisPrimaryExprNode(theParent, exprType, primaryExprTree);
		else if (primaryExprTree.getType() == MintLexer.SUPER)
			expr = new SuperPrimaryExprNode(theParent, exprType, primaryExprTree);
		else if (primaryExprTree.getType() == MintLexer.IntegerLiteral ||
				primaryExprTree.getType() == MintLexer.FloatingPointLiteral ||
				primaryExprTree.getType() == MintLexer.StringLiteral ||
				primaryExprTree.getText().equals("true") ||
				primaryExprTree.getText().equals("false") || 
				primaryExprTree.getText().equals("null"))
			expr = new LiteralNode(theParent, exprType, primaryExprTree);
		else if (primaryExprTree.getType() == MintLexer.NEW)
			expr = new ClassInstanceCreationExprNode(theParent, exprType, primaryExprTree);
		else if (primaryExprTree.getType() == MintLexer.NEWARRAY)
			expr = new ArrayCreationExprNode(theParent, exprType, primaryExprTree);
		else
			expr = new NamePrimaryExprNode(theParent, exprType, primaryExprTree);
	}

	@Override
	public void testSemantic() {
		expr.testSemantic();
	}

	@Override
	public List<String> getSemanticErrors() {		
		return expr.getSemanticErrors();
	}

	@Override
	public void emit(Formatter output) {
		expr.emit(output);
	}

	@Override
	public int getLine() {
		return expr.getLine();
	}

	@Override
	public Type getType() {
		return expr.getType();
	}

	@Override
	public void leftEmit(Formatter output) {
		expr.leftEmit(output);	
	}

}
